package DFS;

import java.util.Scanner;

public class SearchMaxValue {
    static int nums;
    static int volume;
    static int[] weights;
    static int[] values;
    static int max_value = 0;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        nums = sc.nextInt();
        volume = sc.nextInt();
        weights = new int[nums];
        values = new int[nums];
        for(int i = 0;i<nums;i++){
            weights[i] = sc.nextInt();
        }
        for(int i = 0;i<nums;i++){
            values[i] = sc.nextInt();
        }
        getMax(0,0,0);
        System.out.println(max_value);
        System.out.println("nihao");
    }
    public static void getMax(int index,int weight_n,int value_n){
        if(index == nums){
            if(weight_n<=volume && value_n>max_value){
                max_value = value_n;
            }

        }else{
            //要这个物品
            getMax(index+1,weight_n+weights[index],value_n+values[index]);
            //不要这个物品
            getMax(index+1,weight_n,value_n);
        }
    }
}
